#ifndef TRACE_TRACE_GEN_HPP
#define TRACE_TRACE_GEN_HPP

#include "utils/cxx-include.hpp"

#include "toml11/toml.hpp"

#include "core/exception.hpp"
#include "core/log.hpp"
#include "core/random.hpp"

/**
 * \file
 * \ingroup trace
 * cas::TraceGenerator declaration.
 */

namespace cas
{
    /** \ingroup trace */
    template <class T>
    class BaseTask
    {
    public:
        BaseTask();
        virtual ~BaseTask();

        enum TaskStatus
        {
            TASK_INIT,
            TASK_RUN,
            TASK_PAUSE,
            TASK_END,
            TASK_STATUS_NUM
        };

        enum TaskGenType
        {
            TASKGEN_DATA = 0x0001,
            TASKGEN_META = 0x0002,
            TASKGEN_ALL = 0x0003
        };

        virtual inline T next() = 0;

        virtual inline bool isEnd() const { return status == TASK_END; }
        virtual inline bool isRun() const { return status == TASK_RUN; }
        virtual inline void pause()
        {
            if (status == TASK_RUN)
            {
                status = TASK_PAUSE;
            }
        }
        virtual inline void resume()
        {
            if (status == TASK_PAUSE)
            {
                status = TASK_RUN;
            }
        }

        inline virtual std::string typeName() const = 0;

    protected:
        TaskStatus status;
        TaskGenType genType;
        T lastValue;
    };

    /** \ingroup trace */
    class TraceGenerator
    {
    public:
        TraceGenerator(const std::string &configFile = "");
        virtual ~TraceGenerator();

        virtual void loadConfig(const std::string &configFile);
        virtual void loadConfig(std::istream configIstream);

        std::string title; // title

        inline virtual std::string typeName() const = 0;

    protected:
        virtual void parseConfig(const toml::value &config);
    };
}

#endif /* TRACE_TRACE_GEN_HPP */